import * as actionTypes from './constants';
import axios from 'axios';
import { fromJS } from 'immutable';

const initHome = (list, recommend) => ({
  type: actionTypes.INIT_HOME,
  articleList: fromJS(list),
  recommendList: fromJS(recommend),
});

export const initArticleList = () => {
  return (dispatch) => {
    axios
      .get('/api/home.json')
      .then((res) => {
        console.log(res);
        dispatch(initHome(res.data.data.articleList, res.data.data.recommendList));
      })
      .catch((e) => {
        console.log(e);
      });
  };
};
